package saci.util.xml;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class Marshaller {
	
	public void marshal(Object bean, Writer writer) throws IOException {
		marshal(bean, writer, false);
	}
	
	public void marshal(Object bean, OutputStream outputStream) throws IOException {
		marshal(bean, outputStream, false);
	}
	
	public void marshal(Object bean, OutputStream outputStream, boolean prettyPrint) throws IOException {
		marshal(bean, new OutputStreamWriter(outputStream), prettyPrint);
	}
	
	public void marshal(Object bean, Writer writer, boolean prettyPrint) throws IOException {
		XmlWriter xml = new XmlWriter(writer, prettyPrint);
		xml.writeBean(bean);
	}
	
	public <T> T unmarshal(InputStream inputStream, Class<T> type) throws IOException {
		XmlReader xml = new XmlReader(inputStream);
		return xml.fillBean(type);
	}
}
